﻿//====================================================================
// Create by Daniel
// file： YCUserRole.cs
// project ：YunCMS
// Build time：2012-09-22
// modify:
// description:
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using YunCMS.Model;
using YunCMS.IDAL;

namespace YunCMS.BLL
{
    /// <summary>
    /// Business Logic Layer For YCUserRole.
    /// </summary>
    public class YCUserRoleBLL
    {

		///<summary>
		/// DAL Instance.
		///</summary>
		public static readonly IYCUserRoleDAL dal=DALFactory.CreateYCUserRole();
        public static readonly IYCUserActionDAL actionDal = DALFactory.CreateYCUserAction();
        public static readonly string actionSql = "select * from YC_User_Action";
		

		/// <summary>
		/// constructor
		/// </summary>
		public YCUserRoleBLL()
		{
		}

		#region Insert update delete
		/// <summary>
		/// insert a YCUserRole
		/// </summary>
		/// <param name="model">YCUserRole</param>
		/// <returns>The id of the new item</returns>
		public int Add(YCUserRole model)
		{
			// Validate input
			if (model == null)
				return 0;
			// Use the dal to insert a new record 
			return dal.Add(model);
		}

        public int AddWithActions(YCUserRole model)
        {
            if (model == null)
                return 0;

            return dal.AddWithActions(model);
        }

		/// <summary>
		/// update a YCUserRole.
		/// </summary>
		/// <param name="model">YCUserRole</param>
		/// <returns>Rows affected</returns>
		public int Update(YCUserRole model)
		{
            // Validate input
			if (model==null)
				return 0;
			// Use the dal to update a new record 
			return dal.Update(model);
		}

        public int UpdateWithActions(YCUserRole model)
        {
            if (model == null)
                return 0;

            return dal.UpdateWithActions(model);
        }

        public int DeleteWithActions(int ID)
        {
            return dal.DeleteWithActions(ID);
        }
				
		/// <summary>
		/// delete a item
		/// </summary>
	    /// <param name="model">id</param>
		/// <returns>affectes rows</returns>
		public int Remove(int id)
		{
			// Validate input
			if(id<0)
				return 0;
			return dal.Delete(id);
		}
				
        /// <summary>
		/// Get a YCUserRole 
		/// </summary>
		/// <param name="ID">id</param>
		/// <returns>YCUserRole entity</returns>
		public YCUserRole GetYCUserRole(int id)
		{
			// Validate input
			if(id<0)
				return null;

			// Use the dal to get a record 
			return dal.GetYCUserRole(id);
		}

        /// <summary>
        /// Get a YCUserRole 
        /// </summary>
        /// <param name="ID">id</param>
        /// <returns>YCUserRole entity</returns>
        public YCUserRole GetYCUserRoleWithActions(int id)
        {
            // Validate input
            if (id < 0)
                return null;

            // Use the dal to get a record 
            return dal.GetYCUserRoleWithActions(id);
        }
		
		/// <summary>
		/// get YCUserRoles
		/// </summary>
		/// <returns>List</returns>
        public IList<YCUserRole> GetList(string name)
		{
			// Use the dal to get all records 
            return dal.GetList(name);
		}

        /// <summary>
        /// get YCUserRoles
        /// </summary>
        /// <returns>List</returns>
        public IList<YCUserRole> GetList()
        {
            // Use the dal to get all records 
            return dal.GetList();
        }

        public IList<YCUserAction> GetActionList()
        {
            return actionDal.GetList(actionSql);
        }			
		
		/// <summary>
        /// if IsExist a item accroding to id
        /// </summary>
        /// <param name="ID">id</param>
        /// <returns>true/false</returns>
		public bool IsExist(int id)
		{
			return dal.IsExist(id);
		}

        #endregion	
		
    }
}






